#include "stdafx.h"

AnimationMgr::AnimationMgr()
{
}

AnimationMgr::~AnimationMgr()
{
	for (AbstractAnimation * anim : animations)
	{
		delete anim;
	}
}

AnimationMgr * AnimationMgr::getInstance()
{
	static AnimationMgr manager;

	return &manager;
}

void AnimationMgr::add(AbstractAnimation * anim)
{
	animations.push_back(anim);
}

bool AnimationMgr::update(double dtime)
{
	std::vector<AbstractAnimation *>::iterator it = animations.begin();

	while (it != animations.end())
	{
		if ((*it)->update(dtime))
		{
			it++;
		}
		else
		{
			it = animations.erase(it);
		}
	}

	return true;
}

bool AnimationMgr::render()
{
	for (AbstractAnimation * anim : animations)
	{
		anim->render();
	}

	return true;
}

bool AnimationMgr::clear()
{
	for (AbstractAnimation * anim : animations)
	{
		delete anim;
	}

	animations.clear();

	return true;
}